<?php
/**
 * File:          KValidatorCache
 * Description:   -
 * Author:        Kovac "Kovacou'" Alexandre (www.kovacou.fr)
 * Last Update:   10/04/2011
 */

   class KValidatorCache {
      const FORCE = 0,
            EXPIRE = 1,
            UPDATE = 2;

      protected $pathCache,
                $mod,
                $fileTime,
                $fileCreated,
                $filemtime;
      
      public function __construct ($dirCache, $mod, $file, $time = 0) {
         $this->pathCache   = $dirCache . $file . ".cache";
         $this->mod         = (int) $mod;
         $this->fileCreated = file_exists ($this->pathCache);

         if ($this->fileCreated) {
            $this->expire = (filemtime ($this->pathCache) + (int) $time < time());
            $this->fileTime = (int) $time;
         }
      }

      public function expire () {
         if ( $this->mod === self::FORCE || $this->fileCreated === false || ($this->mod === self::EXPIRE && $this->expire === true) || ($this->mod === self::UPDATE && filemtime ($this->pathCache) < $this->fileTime) )
            return true;

         return false;
      }

      public function written ($content) {
         return file_put_contents($this->pathCache, $content);
      }

      public function getPath () {
         return $this->pathCache;
      }
   }
 
/**
 * End
 * Of
 * File
 */
?>